<?php
//by willson 105328468@qq.com 2014/10/11
//index page interface
//我的提现账户
class bank extends core {

	public function __construct() {
		parent::__construct();
	}

	public function mybank() {
		$sql = "SELECT * FROM jf_bank_account WHERE member_id='{$this->member_id}' ORDER BY id ASC";
		$banks = $this->db->get_results($sql);
		success($banks);
	}

	public function add() {
		$this->add_edit();
	}

	public function edit() {
		$this->add_edit();
	}

	public function add_edit() {
		$id = (isset($_POST['id']) && trim($_POST['id'])) ? intval($_POST['id']) : 0;
		$name = (isset($_POST['name']) && trim($_POST['name'])) ? trim($_POST['name']) : '';
		$bank_name = (isset($_POST['bank_name']) && trim($_POST['bank_name'])) ? trim($_POST['bank_name']) : '';
		$card_number = (isset($_POST['card_number']) && trim($_POST['card_number'])) ? trim($_POST['card_number']) : '';
		$branch_name = (isset($_POST['branch_name']) && trim($_POST['branch_name'])) ? trim($_POST['branch_name']) : '';
		if ($id) {
			$sql = "UPDATE jf_bank_account SET name='{$name}', bank_name='{$bank_name}', card_number='{$card_number}', branch_name='{$branch_name}' 
				WHERE id='{$id}' AND member_id='{$this->member_id}'";
			$this->db->query($sql);
		} else {
			$sql = "INSERT INTO jf_bank_account(member_id, name, bank_name, card_number, branch_name, add_time) 
				VALUES('{$this->member_id}', '{$name}', '{$bank_name}', '{$card_number}', '{$branch_name}', '".time()."')";
			$this->db->query($sql);
			$id = $this->db->insert_id;			
		}
		$sql = "SELECT * FROM jf_bank_account WHERE member_id='{$this->member_id}' AND id='{$id}'";
		$banks = $this->db->get_row($sql);
		success($banks);
	}

	public function delete() {
		$id = (isset($_POST['id']) && trim($_POST['id'])) ? intval($_POST['id']) : 0;
		$sql = "DELETE FROM jf_bank_account  WHERE id='{$id}' AND member_id='{$this->member_id}'";
		$this->db->query($sql);
		success("ok");
	}
}
